//
//  Seach_FiltrateSetingList_Collection_Moudle_WX.m
//  ZITHER
//
//  Created by weixin on 2019/3/19.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "Seach_FiltrateSetingList_Collection_Moudle_WX.h"
#import "Seach_FiltrateBrand_CollectionViewCell_WX.h"
#import "Seach_FiltrateAttribute_CollectionViewCell_WX.h"
#import "Seach_FiltrateAttributeSup_CollectionViewCell_WX.h"

@implementation Seach_FiltrateSetingList_Collection_Moudle_WX

-(void)setArrTitle:(NSMutableArray *)arrTitle{
    _arrTitle = arrTitle;
    self.contentOffset = CGPointMake(0, 0);
    [self reloadData];
}


- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout{
    self = [super initWithFrame:frame collectionViewLayout:layout];
    if (self) {
        
        //CGRectMake(0,94, SCREEN_WIDTH, SCREEN_HEIGHT-137)
        
        self.delegate=self;
        
        self.dataSource=self;
        
        self.bounces=NO;
        
        self.pagingEnabled=YES;
        
        self.backgroundColor=[UIColor whiteColor];
        
        [self registerClass:[Seach_FiltrateBrand_CollectionViewCell_WX class] forCellWithReuseIdentifier:@"Seach_FiltrateBrand_CollectionViewCell_WX"];
        [self registerClass:[Seach_FiltrateAttribute_CollectionViewCell_WX class] forCellWithReuseIdentifier:@"Seach_FiltrateAttribute_CollectionViewCell_WX"];
        [self registerClass:[Seach_FiltrateAttributeSup_CollectionViewCell_WX class] forCellWithReuseIdentifier:@"Seach_FiltrateAttributeSup_CollectionViewCell_WX"];
        
        
        
        self.showsVerticalScrollIndicator = NO;
        
        self.showsHorizontalScrollIndicator = NO;
        //        BaseTbv Seach_FiltrateBrand_CollectionViewCell_WX
        
        
        
        _dicM = [NSMutableDictionary dictionary];
        
    }
    return self;
}


#pragma  mark--collection代理方法
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.arrTitle.count;
}

//创建复用tableView
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return [self getSeach_FiltrateBrand_CollectionViewCell_WX:indexPath];
    }else if (indexPath.row == 1 ){
        return [self getSeach_FiltrateAttribute_CollectionViewCell_WX:indexPath];
    }else{
        return [self getSeach_FiltrateAttributeSup_CollectionViewCell_WX:indexPath];

    }
}

-(Seach_FiltrateBrand_CollectionViewCell_WX*)getSeach_FiltrateBrand_CollectionViewCell_WX:(NSIndexPath *)indexPath{
    Seach_FiltrateBrand_CollectionViewCell_WX *cell=[self dequeueReusableCellWithReuseIdentifier:@"Seach_FiltrateBrand_CollectionViewCell_WX" forIndexPath:indexPath];
    
    cell.indexBox = indexPath.row;
    cell.arrTitle = self.arrTitle;
    NSMutableArray *arrM = [self setdic:[NSString stringWithFormat:@"%ld",indexPath.row]];
    cell.arrM = arrM;
    
    [cell setBlcok:^(NSInteger index, NSMutableArray *arrM) {
        [self.dicM setValue:arrM forKey:[NSString stringWithFormat:@"%ld",index]];
        //        [self reloadData];
    }];
    self.TB = cell.TB;

    return cell;
}
-(Seach_FiltrateAttribute_CollectionViewCell_WX*)getSeach_FiltrateAttribute_CollectionViewCell_WX:(NSIndexPath *)indexPath{
    Seach_FiltrateAttribute_CollectionViewCell_WX *cell=[self dequeueReusableCellWithReuseIdentifier:@"Seach_FiltrateAttribute_CollectionViewCell_WX" forIndexPath:indexPath];
    
    cell.indexTbv = indexPath.row;
    
//    cell.indexBox = indexPath.row;
//    cell.arrTitle = self.arrTitle;
//    NSMutableArray *arrM = [self setdic:[NSString stringWithFormat:@"%ld",indexPath.row]];
//    cell.arrM = arrM;
//
//    [cell setBlcok:^(NSInteger index, NSMutableArray *arrM) {
//        [self.dicM setValue:arrM forKey:[NSString stringWithFormat:@"%ld",index]];
//        //        [self reloadData];
//    }];
//    self.TB = cell.TB;

    return cell;
}

-(Seach_FiltrateAttributeSup_CollectionViewCell_WX *)getSeach_FiltrateAttributeSup_CollectionViewCell_WX:(NSIndexPath *)indexPath{
//    NSString * cellStr = [NSString stringWithFormat:@"%@%ld", @"Seach_FiltrateAttributeSup_CollectionViewCell_WX",indexPath.row];
    Seach_FiltrateAttributeSup_CollectionViewCell_WX *cell=[self dequeueReusableCellWithReuseIdentifier:@"Seach_FiltrateAttributeSup_CollectionViewCell_WX" forIndexPath:indexPath];
    cell.indexTbv = indexPath.row;
    cell.backgroundColor = baseColorTheme;
    return cell;
}



//    WxFirstCollectionCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
//
//    //    for(id subView in cell.contentView.subviews){
//    //
//    //        if(subView){
//    //
//    //            [subView removeFromSuperview];
//    //
//    //        }
//    //    }
//
//    //        cell.backgroundColor = WXColor;
//    cell.indexBox = indexPath.row;
//    cell.arrTitle = self.arrTitle;
//    NSMutableArray *arrM = [self setdic:[NSString stringWithFormat:@"%ld",indexPath.row]];
//    cell.arrM = arrM;
//
//    [cell setBlcok:^(NSInteger index, NSMutableArray *arrM) {
//        [self.dicM setValue:arrM forKey:[NSString stringWithFormat:@"%ld",index]];
//        //        [self reloadData];
//    }];
//
//    if (arrM.count==0) {
//        [cell.TB.mj_header beginRefreshing];
//
//        //需要优化:推荐没数据时候会出现数据
//        //        if (indexPath.row!=0) {
//        //            [cell.TB reloadData];
//        //        }
//
//    }else{
//        cell.TB.arrM = arrM;
//    }
//
//    return cell;
//}
//
//
#pragma mark --  scrollView代理方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//    for (int i =0; i<self.arrTitle.count; i++) {
//        if (scrollView.contentOffset.x==SCREEN_WIDTH*i) {
//            CGFloat index = scrollView.contentOffset.x/SCREEN_WIDTH;
//            NSLog(@"scrollView.contentOffset.x = %f",index);
//            NSString *str = [NSString stringWithFormat:@"%f",index];
//            NSInteger i = [str integerValue];
//        }
//    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    //blockEndIndex
    NSLog(@"结束滑动  ===  %f",scrollView.contentOffset.x/kScreenW);
    NSInteger index = scrollView.contentOffset.x/kScreenW;
    _block(index);

}

- (BOOL)isPureInt:(NSString*)string{
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return[scan scanInt:&val] && [scan isAtEnd];
}

- (BOOL)isPureNumandCharacters:(NSString *)string
{
    string = [string stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]];
    if(string.length > 0)
    {
        return NO;
    }
    return YES;
}

-(NSMutableArray *)setdic:(NSString*)index
{
    NSMutableArray *arrM =self.dicM[index];
    if (arrM ==nil) {
        arrM = [[NSMutableArray alloc]init];
        [self.dicM setObject:arrM forKey:index];
    }
    return arrM;
}

-(void)setDicM:(NSMutableDictionary *)dicM
{
    _dicM = dicM;
    [self reloadData];
}

-(void)setIndex:(NSInteger)index
{
    _index = index;
    [self reloadData];
}


@end
